import { TokenRequestData, TableResponseData } from '@/types/interface'
import {
  DepositRefundType,
  AccountType,
  RefundStatus,
  BizType,
  RefundApplyType,
  CustomerRefundType,
  ShortTermAdjustType,
  OperationType,
  FeeType,
  AppealStatus,
  depositDeductionOperationType,
  CyclingGrievancesFeeType
} from '@/types/enum'
/**
 * 获取长租押金退款
 */
export interface queryDepositRefundRequestData extends TokenRequestData {
  orderId: string
  orderDetailId: string
  orderType: string
  status: DepositRefundType
  submitter: string
}
export type OriginAccountData = '-'
export interface AlipayAccountData {
  aliName: string
  aliAccount: string
}
export interface BankCardAccountData {
  bankName: string
  bankBranchName: string
  username: string
  card: string
}
export interface refusedListTableCol {
  createdTime: string
  applyAmount: string
  accountType: AccountType
  accountData: OriginAccountData | AlipayAccountData | BankCardAccountData | Record<string, any>
  state: DepositRefundType
  approvalResult: string
  approvalTime: string
  submitter: string
}
export interface queryDepositRefundTableCol {
  mobilePhone: string
  orderId: string
  orderType: string
  remainDuration: string
  refundAmount: string
  applyAmount: string
  accountOperation: string
  createdTime: string
  applyReason: string
  accountType: AccountType
  updatedTime: string
  depositOrderId: string
  state: DepositRefundType
  approvalResult: string
  submitter: string
  approver: string
  userId: string
  refusedList: refusedListTableCol[]
}

export type queryDepositRefundResponseData = TableResponseData<queryDepositRefundTableCol>
export type queryDepositRefundResponse = ApiResponseData<queryDepositRefundResponseData>

/**
 * 查看退款记录
 */

export interface queryRefundApplyRequestData extends TokenRequestData {
  orderId: string
}

export interface queryRefundApplyResponseData {
  orderId: string
  status: RefundStatus
  createdTime: string
  submitter: string
  mobilePhone: string
  orderType: BizType
  applyType: RefundApplyType
  applyAmount: string
  applyReason: string
  accountType: AccountType
  accountData: OriginAccountData | AlipayAccountData | BankCardAccountData | Record<string, any>
}

export type queryRefundApplyResponse = ApiResponseData<queryRefundApplyResponseData[]>

/** 查询退款详情 */
export interface queryRefundDetailRequestData extends TokenRequestData {
  orderId: string
}

export interface refundDataByStepType {
  title: string
  approveTime: string
  operator: string
}
export interface queryRefundDetailResponseData {
  userPhone: string //手机号
  orderId: string //订单id
  refundType: string //退款类型
  refundRent: string //退款租金
  refundDeposit: string //退款押金
  refundPath: string //退款渠道
  refundOrderId: string //退款订单id
  refundData: refundDataByStepType[]
  step: string
}
export type queryRefundDetailResponse = ApiResponseData<queryRefundDetailResponseData>

/** 获取客服退款列表 */
export interface queryCmRefundApplyRequestData extends TokenRequestData {
  phone: string
  orderId?: string
  orderDetailId?: string
  orderType?: string
  status: CustomerRefundType
}

export interface queryCmRefundApplyTableCol {
  mobilePhone: string
  orderId: string
  orderType: string
  remainDuration: string
  refundAmount: string
  applyAmount: string
  accountOperation: string
  createdTime: string
  applyReason: string
  accountType: AccountType
  updatedTime: string
  depositOrderId: string
  state: DepositRefundType
  approvalResult: string
  submitter: string
  approver: string
  userId: string
  refusedList: refusedListTableCol[]
}
export type queryCmRefundApplyResponseData = TableResponseData<queryCmRefundApplyTableCol>

export type queryCmRefundApplyResponse = ApiResponseData<queryCmRefundApplyResponseData>

/** 提交退款申请 */
export interface submitCmRefundApplyRequestData extends TokenRequestData {
  orderId: string
  applyAmount?: number
  applyReason?: string
  accountType?: string
  remainDuration?: string
  accountData?: Record<string, any>
  applyType: 'PARTIAL_REFUND' | 'DEPOSIT_REFUND'
  type: string
  day?: number
  hour?: number
  minute?: number
  times?: number
}

export type submitCmRefundApplyResponse = ApiResponseData<string>

export interface calculateRefundAmountRequestData extends TokenRequestData {
  orderId: string
  type: '0' | '1'
  day?: number
  hour?: number
  minute?: number
  times?: number
}
export type calculateRefundAmountResponse = ApiResponseData<string>
export interface resubmitDepositRefundRequestData extends TokenRequestData {
  orderId: string
  accountData?: Record<string, any>
}
export type resubmitDepositRefundResponse = ApiResponseData<string>
/**
 * 短租车收/退费
 * @param operateType 0 退费 1 收费
 * @param couponReturn 0 不退回 1退回
 */
export interface shortTermChargeRefundRequestData extends TokenRequestData {
  orderId: string
  applyAmount: number
  type: ShortTermAdjustType
  operateType: 0 | 1
  reason: string
  couponReturn: 0 | 1
}

export type shortTermChargeRefundResponse = ApiResponseData<string>

export interface queryShortTermChargeRefundRequestData extends TokenRequestData {
  phone: string
  orderId: string
  operationType: ShortTermAdjustType | ''
  type: OperationType | ''
}

export interface queryShortTermChargeRefundTabelCol {
  phone: string
  orderId: string
  changeTime: string
  reason: string
  rideAmount: string
  forceReturnAmount: string
  deductionType: string
  payStatus: string
  operationType: string
  amount: string
  discountCoupon: string
  operator: string
}

export type queryShortTermChargeRefundResponseData =
  TableResponseData<queryShortTermChargeRefundTabelCol>

export type queryShortTermChargeRefundResponse =
  ApiResponseData<queryShortTermChargeRefundResponseData>

/** 查询其他收费 */
export interface queryOtherChargeRequestData extends TokenRequestData {
  phone: string
  orderId: string
  operationType: '' | ShortTermAdjustType
}
export interface queryOtherChargeTableCol {
  phone: string
  bikeCode: string
  orderId: string
  operationType: string
  reason: string
  imageUrls: null | string
  payStatus: string
  amount: string
  changeTime: string
  operator: string
  payTime: string
  paymentType: string
  tradeNo: string
  remark: string
  feeChangeId: string
  remainingRefundAmount: number
}

export type queryOtherChargeResponseData = TableResponseData<queryOtherChargeTableCol>

export type queryOtherChargeResponse = ApiResponseData<queryOtherChargeResponseData>

/** 新建其他收费 */
export interface otherChargeRefundRequestData extends TokenRequestData {
  orderId: string
  applyAmount: number
  type: ShortTermAdjustType
  operateType: OperationType
  imageUrls?: string
  reason: string
  phone?: string
  bikeCode?: string
  feeChangeId?: string
}

export type otherChargeRefundResponse = ApiResponseData<string>

/** 其他收费待付调整  */
export interface adjustOtherChargeRequestData extends TokenRequestData {
  feeChangeId: string
  applyAmount: number
  reason: string
}

export type adjustOtherChargeResponse = ApiResponseData<string>

/** 获取申诉审批 */
export interface queryOrderAppealRequestData extends TokenRequestData {
  phone: string
  name: string
  feeType: CyclingGrievancesFeeType
}
/**
 * @description 申诉列表
 * @param processed 0 未处理 1已处理 （只有申诉通过的才需要处理）
 * @param orderAppealId 申诉编号
 */
export interface queryOrderAppealTableCol {
  orderId: string
  feeType: CyclingGrievancesFeeType
  name: string
  phone: string
  appealDate: string
  appealReason: string
  imageUrls: string
  status: AppealStatus
  reviewTime: string
  resolution: string
  appealCount: string
  processed: 0 | 1
  processedTime: string
  orderAppealId: number
  amount: number
  storeName: string
  feeChangeId: number
  appealType: string
  bikeCode: string
  bikeId: string
  userId: string
}

export type queryOrderAppealResponseData = TableResponseData<queryOrderAppealTableCol>
export type queryOrderAppealResponse = ApiResponseData<queryOrderAppealResponseData>

export interface approveOrderAppealRequestData extends TokenRequestData {
  orderAppealId: number
  resolution: string
  status: '0' | '1'
  amount?: number
  type?: number
}

export type approveOrderAppealResponse = ApiResponseData<string>

/**
 * 提交押金抵扣
 * @param operationType
 */
export interface submitDepositDeductionRequestData extends TokenRequestData {
  orderId: string
  amount: number
  reason: string
  operationType: depositDeductionOperationType
  remark?: string
}

export type submitDepositDeductionResponse = ApiResponseData<string>

export interface queryDepositDeductionRequestData extends TokenRequestData {
  orderId: string
}

/**
 * 查询押金抵扣
 */
export interface queryDepositDeductionTableCol {
  type: depositDeductionOperationType
  amount: number
  reason: string
  remainDeposit: string
  createdTime: string
  orderLoggingId: number
}
export type queryDepositDeductionResponseData = TableResponseData<queryDepositDeductionTableCol>

export type queryDepositDeductionResponse = ApiResponseData<queryDepositDeductionResponseData>

export interface revokeDepositDeductionRequestData extends TokenRequestData {
  orderLoggingId: number
}
export type revokeDepositDeductionResponse = ApiResponseData<string>
